package arithmetic;

/**
 * @author jiangfeng on 2022/1/15
 */
public class NumTrans {
    // 金额转化

    public static void main(String[] args) {
        System.out.println(numTrans("5236"));
        System.out.println(numTrans("5036"));
        System.out.println(numTrans("5030"));
        System.out.println(numTrans("5000"));
        System.out.println(numTrans("50"));
        System.out.println(numTrans("23"));
        System.out.println(numTrans("6"));
    }

    /**
     * num小于12位
     * 32526 -> 三万 二千五百二十六
     * 30021 -> 三万 零二十一
     * @param num
     * @return
     */
    public static String numTrans(String num){
        int size = num.length();
        final String zeroS = "零";
        String[] trans = {zeroS,"一","二","三","四","五","六","七","八","九"};

        String[] scale = {"","十","百","千"};

        char[] chars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        char zero = '0';


        String  result = "";
        // 四位及以内
        for (int i = 0; i < num.length(); i++) {
            char c = num.charAt(i);
            result = trans[c - zero]+ scale[i]+ result;
        }


        // 最后处理下零的问题 多个零替换为一个,并且去掉最后一个零
        result= result.replaceAll("(零)+",zeroS);
        if(result.endsWith(zeroS)){
            result=result.substring(0,result.length()-1);
        }

        return result;


    }

    /**
     * 最大支持12位数
     * @param num
     * @return
     */
    public static String numTrans2(int num) {
        if (num < 0) {
            return "负数不支持";
        }
        final int qianyi = (10000 * 10000 * 10);
        final int baiyi = (10000 * 10000 * 10);
        final int shiyi = (10000 * 10000);
        final int yi = (10000 * 1000);
        final int qianwan = (10000 * 1000);
        final int baiwan = (10000 * 100);
        final int shiwan = (10000 * 10);
        final int wan = (10000);
        final int qian = (1000);
        final int bai = (100);
        final int shi = (10);

        final String zeroS = "零";
        String[] trans = {zeroS, "一", "二", "三", "四", "五", "六", "七", "八", "九"};
        char[] chars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        String[] scale = {"十","百","千","万","亿"};
        char zero = '0';
        if (num < shi) {
            return trans[num];
        }
        String numString = String.valueOf(num);
        int numLength = numString.length();
        //char c = numString.charAt(numLength - 1);
        String result = "";

        // 先处理四位数的
        switch (numLength) {
            case 4:
                int a = num/qian;
                result+=(a==0)?zeroS:trans[a]+scale[2];
            case 3:
                int b = num/bai;
                result+=(b==0)?zeroS:trans[b]+scale[1];
            case 2:
                int c = num/shi;
                result+=(c==0)?zeroS:trans[c]+scale[0];
            case 1:
                int d = num/yi;
                result+=(d==0)?"":trans[d]+scale[3];


        }
        return null;

//        if(num<bai){
//            result=
//        }
//
//        result+



    }


}
